//
//  DHVisitorView.m
//  Sina.Weibo.OC
//
//  Created by Holfioo on 15/9/3.
//  Copyright © 2015年 Holfioo. All rights reserved.
//

#import "DHVisitorView.h"

// 扩展类声明相应的属性
@interface DHVisitorView ()

@property (nonatomic, strong) UIImageView *mainCircle;
@property (nonatomic, strong) UIImageView *homeView;

@property (nonatomic, strong) UILabel *messageView;

@end

@implementation DHVisitorView

- (instancetype)initWithFrame:(CGRect)frame
{
    // 注意oc写法
    if (self = [super initWithFrame:frame]) {
        // 加载控件
        [self setupSubviewFrame];
    }
    return self;
}

// 设置控件的属性
- (void)setupSubviewFrame
{
    // 增加控件
    [self addSubview:self.mainCircle];
    [self addSubview:self.homeView];
    [self addSubview:self.messageView];
    
    // 布局控件的frame
    [self.mainCircle setTranslatesAutoresizingMaskIntoConstraints:NO]; // 注意设置自动布局属性为不可用。
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.mainCircle attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant: 0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.mainCircle attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant: -60]];
    
    [self.homeView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.mainCircle attribute:NSLayoutAttributeCenterX multiplier:1 constant: 0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.mainCircle attribute:NSLayoutAttributeCenterY multiplier:1 constant: 0]];
    // 布局信息lab
    [self.messageView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainCircle attribute:NSLayoutAttributeBottom multiplier:1 constant:20]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.mainCircle attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:224]];
    
    
}


// 懒加载相应的属性。
// 转圈的圆
- (UIImageView *)mainCircle
{
    if (_mainCircle == nil) {
        // 创建控件
        _mainCircle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _mainCircle;
}
// 布局中间小房子
- (UIImageView *)homeView
{
    if (_homeView == nil) {
        // 创建控件
        _homeView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeView;
}

- (UILabel *)messageView
{
    if (_messageView == nil) {
        // 设置属性
        _messageView = [[UILabel alloc] init];
        _messageView.text = @"关注一些人，回这里看看有什么";
        _messageView.textColor = [UIColor darkGrayColor];
        _messageView.textAlignment = NSTextAlignmentCenter;
        _messageView.font = [UIFont systemFontOfSize:14];
        _messageView.numberOfLines = 0;
    }
    return _messageView;
}

@end
